const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    videoId: 0,
    videoUrl: '',
    duration: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      videoUrl: options.url,
      videoId: options.videoId,
      duration: options.duration
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  recordWatch() {
    app.fetchRequest({
      url: `/course/watch/save/${this.data.videoId}`,
      data: {
        progress: this.data.duration,
        videoId: this.data.videoId
      },
      success: (res) => { }
    })
  },

  finishWatch() {
    this.recordWatch();
  }
})